package net.wofly.right.validator;


import net.wofly.common.util.CommonStatus;
import net.wofly.right.domain.Organization;
import net.wofly.right.domain.User;
import net.wofly.right.domain.UserRole;
import org.springframework.util.StringUtils;

public class OrganizationValidator {
    
    /**
     * 换行符
     */
    private static String lineSeparator = System.getProperty("line.separator");
    
    public static String validateOrganizationID(String organizationID) {
        StringBuffer stringBuffer = new StringBuffer();
        if (StringUtils.isEmpty(organizationID)) {
            stringBuffer.append("组织机构ID不能为空！").append(lineSeparator);
        }
        return stringBuffer.toString();
    }
    
    public static String validateOrgCode(String orgCode) {
        StringBuffer stringBuffer = new StringBuffer();
        if (StringUtils.isEmpty(orgCode)) {
            stringBuffer.append("组织机构编码不能为空！").append(lineSeparator);
        }
        
        return stringBuffer.toString();
    }
    
    public static String validateModifyOrganizationParams(Organization organization) {
        StringBuffer stringBuffer = new StringBuffer();
        if (null == organization) {
            stringBuffer.append("organization 不能为空").append(lineSeparator);
        } else {
            if (StringUtils.isEmpty(organization.getOptUserID())) {
                stringBuffer.append("当前操作人员用户ID不能为空").append(lineSeparator);
            }
            if (StringUtils.isEmpty(organization.getOrganizationID())) {
                stringBuffer.append("组织机构ID不能为空").append(lineSeparator);
            }
            if (StringUtils.isEmpty(organization.getOrganizationName())) {
                stringBuffer.append("组织机构名称organizationName不能为空").append(lineSeparator);
            }
            if (StringUtils.isEmpty(organization.getOrganizationCode())) {
                stringBuffer.append("组织机构编码organizationCode不能为空").append(lineSeparator);
            } else {
                if (organization.getOrganizationCode().length() % 3 != 0) {
                    stringBuffer.append("组织机构编码organizationCode长度不正确").append(lineSeparator);
                }
            }
            if (null == organization.getWarehouseFlag() || !CommonStatus.isValueCorrect(
                    organization.getWarehouseFlag())) {
                stringBuffer.append("是否有仓库标识warehouseFlag不能为空").append(lineSeparator);
            }
        }
        return stringBuffer.toString();
    }
    
    public static String validateAddSubOrganizationParams(String organizationID, Organization organization) {
        StringBuffer stringBuffer = new StringBuffer();
        if (StringUtils.isEmpty(organizationID)) {
            stringBuffer.append("父级组织机构ID不能为空！").append(lineSeparator);
        }
        if (null == organization) {
            stringBuffer.append("organization 不能为空").append(lineSeparator);
        } else {
            if (StringUtils.isEmpty(organization.getOptUserID())) {
                stringBuffer.append("当前操作人员用户ID不能为空").append(lineSeparator);
            }
            if (StringUtils.isEmpty(organization.getOrganizationName())) {
                stringBuffer.append("组织机构名称organizationName不能为空").append(lineSeparator);
            }
            if (StringUtils.isEmpty(organization.getOrganizationCode())) {
                stringBuffer.append("组织机构编码organizationCode不能为空").append(lineSeparator);
            } else {
                if (organization.getOrganizationCode().length() % 3 != 0) {
                    stringBuffer.append("组织机构编码organizationCode长度不正确").append(lineSeparator);
                }
            }
            if (null == organization.getWarehouseFlag() || !CommonStatus.isValueCorrect(
                    organization.getWarehouseFlag())) {
                stringBuffer.append("是否有仓库标识warehouseFlag不能为空").append(lineSeparator);
            }
        }
        return stringBuffer.toString();
    }
    
    public static String validateAddOrganizationParams(Organization organization) {
        StringBuffer stringBuffer = new StringBuffer();
        if (null == organization) {
            stringBuffer.append("organization 不能为空").append(lineSeparator);
        } else {
            if (StringUtils.isEmpty(organization.getOrganizationName())) {
                stringBuffer.append("组织机构的名称不能为空").append(lineSeparator);
            }
            if (StringUtils.isEmpty(organization.getWarehouseFlag())) {
                stringBuffer.append("组织机构的仓库标识不能为空").append(lineSeparator);
            }
        }
        return stringBuffer.toString();
    }
    
    public static String validateUpdateOrganizationParams(Organization organization) {
        StringBuffer stringBuffer = new StringBuffer();
        if (null == organization) {
            stringBuffer.append("organization 不能为空").append(lineSeparator);
        } else {
            if (StringUtils.isEmpty(organization.getOrganizationID())) {
                stringBuffer.append("组织机构ID不能为空").append(lineSeparator);
            }
            if (StringUtils.isEmpty(organization.getOrganizationName())) {
                stringBuffer.append("组织机构的名称不能为空").append(lineSeparator);
            }
            if (StringUtils.isEmpty(organization.getWarehouseFlag())) {
                stringBuffer.append("组织机构的仓库标识不能为空").append(lineSeparator);
            }
        }
        return stringBuffer.toString();
    }
    
    public static String validateGetUserByOrganizationParams(String organizationID) {
        StringBuffer stringBuffer = new StringBuffer();
        if (StringUtils.isEmpty(organizationID)) {
            stringBuffer.append("组织机构ID不能为空").append(lineSeparator);
        }
        return stringBuffer.toString();
    }
    
    public static String validateSetUserRoleParams(UserRole userRole) {
        StringBuffer stringBuffer = new StringBuffer();
        if (userRole == null) {
            stringBuffer.append("userRole 不能为空").append(lineSeparator);
        } else {
            if (StringUtils.isEmpty(userRole.getSetUserID())) {
                stringBuffer.append("setUserID 不能为空").append(lineSeparator);
            }
            if (StringUtils.isEmpty(userRole.getUserID())) {
                stringBuffer.append("userID 不能为空").append(lineSeparator);
            }
            if (StringUtils.isEmpty(userRole.getRoleID())) {
                stringBuffer.append("roleID 不能为空").append(lineSeparator);
            }
        }
        return stringBuffer.toString();
    }
    
    public static String validateUpdateUserParams(User user) {
        StringBuffer stringBuffer = new StringBuffer();
        if (null == user) {
            stringBuffer.append("user 不能为空").append(lineSeparator);
        } else {
            if (StringUtils.isEmpty(user.getUserID())) {
                stringBuffer.append("员工的ID不能为空").append(lineSeparator);
            }
            if (StringUtils.isEmpty(user.getOrganizationID())) {
                stringBuffer.append("员工的组织机构ID不能为空").append(lineSeparator);
            }
            if (StringUtils.isEmpty(user.getMobile())) {
                stringBuffer.append("员工的手机号码不能为空").append(lineSeparator);
            }
            if (StringUtils.isEmpty(user.getPassword())) {
                stringBuffer.append("员工的密码不能为空").append(lineSeparator);
            }
        }
        return stringBuffer.toString();
    }
    
    public static String validateGetRightConfigByRoleIDParams(String roleID) {
        StringBuffer stringBuffer = new StringBuffer();
        if (null == roleID) {
            stringBuffer.append("roleID不能为空").append(lineSeparator);
        }
        return stringBuffer.toString();
    }
}
